//
//  NearUserCell.m
//  SportSocial
//
//  Created by yull on 14/12/28.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "NearUserCell.h"
#import <CoreLocation/CoreLocation.h>
#import "LocationManager.h"

@implementation NearUserCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.distanceLabel = [[UILabel alloc] initWithFrame:self.nameLabel.frame];
        self.distanceLabel.left = self.contentView.width - 60;
        self.distanceLabel.width = 55;
        self.distanceLabel.textAlignment = NSTextAlignmentRight;
        self.distanceLabel.font = [UIFont systemFontOfSize:13.0f];
        self.distanceLabel.textColor = [UIColor grayColor];
        self.distanceLabel.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.distanceLabel];
    }
    return self;
}

+ (CGFloat)nearCellDefaultHeight
{
    return 70.0f;
}

- (void)drawCellWithNearUser:(NearUser *)nearUser
{
    [super drawCellWithFriendInfo:nearUser];
    
    CLLocation* dist = [[CLLocation alloc] initWithLatitude:nearUser.latitude longitude:nearUser.longitude];
    self.distanceLabel.text = [NSString stringWithFormat:@"%.2fkm",[[LocationManager shareInstance].location distanceFromLocation:dist]/1000];
}

- (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsMake(0, self.nameLabel.left, 0, 0);
}
@end
